import config
import obj_config

# from language import language


class All_programm:
    def __init__(self):
        self.dict_funcs = {}
        self.text_cmd = []
        self.list_funcs = []
        self.text_cmd_info = []
        self.message_void = ""
        self.dict_funcs = {}
        self.list_text_name = []
        self.text_cmd_info_write_list = []
        self.update_source_program()

    def template_info_func(self, id, values):
        mess = f'Индекс {id} {config.cmds_void[values]["word_list"][0]}'
        self.text_cmd.append(values)
        self.list_funcs.append(values)
        self.text_cmd_info.append(mess)
        self.text_cmd_info_write_list.append(
            f'Индекс {id} {config.cmds_void[values]["word_list"][0]}'
        )
        for index, value in enumerate(config.cmds_void[values]["word_list"]):
            mess = f"{mess} {value}  "
            f"Индекс {id} {value}"
        mess = f"{mess}\t"
        for label in config.cmds_void[values]["label_value"]:
            mess = f"{mess}Метки {label} "
        for key in config.cmds_void[values]:
            if key in config.json_log_info_func:
                mess = f"{mess}\n\t {config.json_log_info_func[key][config.cmds['void'][values][key]]}"
        mess = f"{mess}\n"
        if config.cmds_void[values]["function_classification"] in self.dict_funcs:
            self.dict_funcs[config.cmds_void[values]["function_classification"]].append(
                values
            )
        elif not (
            config.cmds_void[values]["function_classification"] in self.dict_funcs
        ):
            self.dict_funcs[config.cmds_void[values]["function_classification"]] = []
            self.dict_funcs[config.cmds_void[values]["function_classification"]].append(
                values
            )
        return mess

    def update_source_program(self):
        mess = ""
        self.message_void = ""
        self.text_cmd.clear()
        self.list_funcs.clear()
        self.text_cmd_info.clear()
        self.dict_funcs.clear()
        self.list_text_name.clear()
        self.text_cmd_info_write_list.clear()
        for index1, values in enumerate(config.cmds_void):
            mess = f"{mess} {self.template_info_func(index1, values)}"
        self.message_void = mess

    def call_program_index_cmd_name(self) -> list:
        # Печатаем все программы
        # obj_config.communication_obj.list_message_enter(self.list_funcs,self.text_cmd_info)
        # obj_config.communication_obj.\
        # turning_on_message(language['all_program=>All_program=>parser_program=>call_program_index']['mess'])
        # выбираем по индексу
        obj_config.communication_obj.list_message_enter(self.text_cmd_info)
        config.decoder_tags_vs_str = "tags"
        index = obj_config.wrapper_decoders_obj.selection_file_decoders(self.list_funcs)
        if index != -1:
            return [self.list_funcs[index]]
        else:
            return ["core_utilities_no_m_error"]

    def call_program_index_text_name(self) -> list:
        # Печатаем все программы
        index = obj_config.communication_obj.menu(self.text_cmd_info_write_list)
        if index != -1:
            return [self.list_funcs[index]]
        else:
            return ["core_utilities_no_m_error"]
